<template>
  <div id="class_room">
    <div class="class_room_info">
      <div class="info_title">
        <div class="title">
          <span class="title_item" style="cursor: pointer;" @click="gotoCourse()">个人中心</span>
          <span class="title_item" style="color:#666666;">> 网络教室</span>
        </div>
      </div>
      <div class="line"></div>
      <div class="calss_room_setting">
        <div class="class_room_login">
          <el-input clearable v-model="roomSerialNum" class="login_input" placeholder="教室房间号"></el-input>
          <el-button type="primary" @click="submit()" class="class_room_btn">进入教室</el-button>
        </div>
        <div class="class_room_tips" style="margin-top:0.1rem;">注：此通道为设备调试和设备异常的学员进入教室使用</div>
        <div class="class_room_tips">
          正常上课流程：
          <a class="tips_go" @click="gotoCourse()">登录->个人中心->我的课程->课程名称->进入教室</a>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
let vm;
export default {
  data: function() {
    return {
      roomSerialNum: ""
    };
  },
  components: {},
  methods: {
    gotoCourse() {
      router.push({
        path: "/personal_center/person_curriculum"
      });
    },
    submit() {
      console.log(vm.$store.state.user);
      let user = tool.clone(vm.$store.state.user);
      if(user == null){
        this.$message.warning("请先登录！");
        return;
      }
      if (vm.roomSerialNum == "") {
        this.$message.warning("请输入教室房间号");
        return;
      }
      let userName = user.clueEntity.realName == "" || user.clueEntity.realName == null ? user.username :user.clueEntity.realName;
      api
        .getEntryRoomUrl({ roomSerialNum: vm.roomSerialNum,userName: userName})
        .then(function(data) {
          if (data.resultCode == 2000) {
            if (!tool.isChrome()) {
              vm.$alert("小鳄鱼课堂仅支持谷歌浏览器", "小鳄鱼课堂", {
                confirmButtonText: "谷歌浏览器下载",
                type: "warning",
                center: true
              })
                .then(() => {
                  window.open("https://www.google.cn/chrome/");
                })
                .catch(() => {});
            } else {
              window.open(data.info, "_blank");
            }
          } else {
            vm.$message.error(data.message);
          }
        });
    }
  },
  created: function() {
    vm = this;
  }
};
</script>

<style lang="scss" scoped>
#class_room {
  overflow-y: auto;
  overflow-x: hidden;
  background: #f4f4f4;
  padding-top: 0.28rem;
  .class_room_info {
    width: 12.1rem;
    margin: 0 auto;
    overflow: hidden;
    height: 7rem;
    
    background-color: #ffffff;
    .info_title {
      overflow: hidden;
      padding: 0.23rem 0.34rem 0.16rem;
      font-size: 0.2rem;
      color: #333333;
      .title {
        float: left;
        .title_item {
          color: #999999;
        }
        .title_item:hover{
          color: #666666;
        }
      }
    }
    .line {
      width: 100%;
      height: 1px;
      background: #bbbbbb;
    }
    .calss_room_setting {
      margin-top: 0.4rem;
      text-align: center;
      .class_room_login {
        width: 4rem;
        height: 2.2rem;
        margin: 0 auto;
        border: 1px solid #cccccc;
        border-radius: 0.1rem;
        padding-top: 0.6rem;
        .login_input {
          width: 2.4rem;
          height: 0.55rem;
          margin: 0 auto;
        }
        .class_room_btn {
          width: 2.4rem;
          height: 0.45rem;
          margin: 0 auto;
        }
      }
      .class_room_tips {
        height: 0.3rem;
        line-height: 0.3rem;
        font-size: 0.14rem;
        color: #999999;
        .tips_go {
          text-decoration: underline;
          color: #551a8b;
          cursor: pointer;
        }
      }
    }
  }
}
</style>